﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.IO;
using System.Windows.Forms;
using YArchitech.Controls;
using YArchitech.LIB;
using YArchitech.Revit;

namespace YArchitech.Plumbing
{
	public partial class FormSetSanitaryList : System.Windows.Forms.Form
	{
		public FormSetSanitaryList(SupplyTerminal initSup, SetSanitaryData sanitaryData, List<SupplyTerminal> supplyTerminalList)
		{
			this.InitializeComponent();
			new YJKProcessTools().ShowInTaskbarChange(this);
			this.selSup = initSup;
			this.InitListView(sanitaryData, supplyTerminalList);
			//base.Icon = Resource.YArchitechIcon;
		}

		private void InitListView(SetSanitaryData sanitaryData, List<SupplyTerminal> supplyTerminalList)
		{
			this.listView1.Items.Clear();
			if (string.IsNullOrEmpty(sanitaryData.SupplyTerminalList))
			{
				return;
			}
			ListViewItem listViewItem = null;
			string[] array = sanitaryData.SupplyTerminalList.Split(new char[]
			{
				','
			});
			for (int i = 0; i < array.Length; i++)
			{
				int num = int.Parse(array[i]);
				if (num > 0)
				{
					foreach (SupplyTerminal supplyTerminal in supplyTerminalList)
					{
						if (File.Exists(supplyTerminal.Image) && num == supplyTerminal.Id)
						{
							Bitmap bitmap = new Bitmap(Image.FromFile(supplyTerminal.Image), 50, 50);
							bitmap.Tag = supplyTerminal;
							this.listView1.LargeImageList.Images.Add(supplyTerminal.Name, bitmap);
							ListViewItem listViewItem2 = new ListViewItem();
							listViewItem2.Tag = supplyTerminal;
							listViewItem2.ImageKey = supplyTerminal.Name;
							if (this.selSup != null && this.selSup.KeyWord == supplyTerminal.KeyWord)
							{
								listViewItem = this.listView1.Items.Add(listViewItem2);
								break;
							}
							this.listView1.Items.Add(listViewItem2);
							break;
						}
					}
				}
			}
			if (listViewItem != null)
			{
				listViewItem.Selected = true;
			}
		}

		private void button1_Click(object sender, EventArgs e)
		{
			this.selSup = null;
			if (this.listView1.Items.Count > 0)
			{
				foreach (object obj in this.listView1.Items)
				{
					ListViewItem listViewItem = (ListViewItem)obj;
					if (listViewItem.Selected)
					{
						this.selSup = (listViewItem.Tag as SupplyTerminal);
						break;
					}
				}
			}
			if (this.selSup == null)
			{
				YJKMessageBox.Show("选择不能为空！");
				return;
			}
			base.DialogResult = DialogResult.OK;
		}

		private void button2_Click(object sender, EventArgs e)
		{
			base.Close();
		}

		public SupplyTerminal selSup;
	}
}
